package main

import (
	"fmt"
//	"github.com/mmitton/asn1-ber"
	"github.com/mmitton/ldap"
)

var ldap_server string="10.99.201.86"//"10.122.0.173"
var ladp_port uint16=10389
var base_dn string="ou=users,ou=plmdeploy,dc=lenovo,dc=com"
var attributes []string=[]string{
	"uid",
	"mail",
}

func main(){
	simpleLDAP_example()
}

func simpleLDAP_example(){
	fmt.Println("Start to test LDAP ...")
	
	//start to connect
	l,err:=ldap.Dial("tcp",fmt.Sprintf("%s:%d",ldap_server,ladp_port))
	if err!=nil {
		fmt.Println("Dail Error:",err.Error())
		return
	}
	defer l.Close()
	//end of connection
	//search
	search_request:=ldap.NewSearchRequest(
		base_dn,
		ldap.ScopeWholeSubtree,ldap.DerefAlways,0,0,false,
		"(uid=*)",
		attributes,
		nil)
	sr,err:=l.Search(search_request)
	if err!=nil {
		fmt.Println("Search error:",err.Error())
		return
	}
	fmt.Printf("Test search: %s -> num of entries = %d",search_request.Filter,len(sr.Entries))
	
	
	fmt.Println("End of test LDAP ...")
}